﻿@{
    ViewBag.Title = "发票审批页面";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script type="text/javascript">

        $(document).ready(function () {
            initListCombo();//加载列表的页面下拉框内容

            bindGrid();


            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridApprovalList");
        });




        @*function initListCombo() {
            //#region 分中心
            $.EUIcombobox("#zcenterCode", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                //editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //#endregion*@
        //查询条件下拉框取值
        function initListCombo() {
            //取分中心
            $.EUIcombobox("#zcenterCode", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                    $.EUIcombobox("#StationID", {
                        url: urlstation,
                        valueField: 'ID',
                        textField: 'Name',
                        //prompt: '--请选择--',
                        editable: false,
                        OneOption: [{
                            ID: "",
                            Name: "--请选择--"
                        }]
                    });
                }
            });
            //#endregion
            //#region 出车分站
            $.EUIcombobox("#StationID", {
                url: '@Url.Content("~/Medical/GetStation?code=")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            })

            $('#zAccidentTimeStart').datebox('setValue', $.GetMonthFirstday());
            $('#zAccidentTimeEnd').datebox('setValue', $.GetTomorrow());


        } //页面初始化结束



        function reSearch() {
            $('#gridApprovalList').datagrid({
                pageNumber: 1,
                queryParams: {
                    zAccidentTimeStart: $('#zAccidentTimeStart').datebox('getValue'),
                    zAccidentTimeEnd: $('#zAccidentTimeEnd').datebox('getValue'),
                    zcenterCode: $('#zcenterCode').combobox('getValue')
                    ,StationID: $("#StationID").combobox("getValue")
                    ,personName: $("#personName").textbox("getText")
                }
            });

        }

        function bindGrid() {
            $('#gridApprovalList').datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                singleSelect: true,
                loadMsg: '数据加载中请稍后……',
                url: '@Url.Content("~/IM/I_InvoiceApproval/DataLoad")',
                striped: true,
                pagination: true,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 15,//设置 页容量5为
                pageList: [10, 15, 20],//设置 页容量下拉框
                sortName: 'ApplyTime',
                sortOrder: 'desc',
                remoteSort: true,
                queryParams: {
                    zAccidentTimeStart: $('#zAccidentTimeStart').datebox('getValue'),
                    zAccidentTimeEnd: $('#zAccidentTimeEnd').datebox('getValue'),
                    zcenterCode: $('#zcenterCode').combobox('getValue')
                    , StationID: $("#StationID").combobox("getValue")
                    , personName: $("#personName").textbox("getText")
                },
                frozenColumns: [[
                     { field: "ApplyID", title: "ApplyID", hidden: true, sortable: false },
                       {
                           field: "deletez", title: "撤销", width: '6%', align: "center",
                           formatter: function (value, row, index) {

                               return '<a  id="adelete" class="linkURLdelete" onclick="deleteDetailURL(\'' + row.ApplyID + '\');"  href="javascript:void(0)">撤销</a>';
                           }
                       },
                   //{ field: "backup1", title: "分中心", width: '5%', align: "center", sortable: false },
                   { field: "backup1", title: "分站", width: '5%', align: "center", sortable: false },
                   { field: "ApplyUserName", title: "申领人", width: '6%', align: "center", sortable: true },
                   { field: "ApplyUserID", title: "申领人工号", width: '5%', align: "center", sortable: true },
                   { field: "ApplyTime", title: "申领时间", width: '9%', align: "center", formatter: $.formatTime, sortable: true }, //金杯救护车
                   { field: "ApplyCount", title: "申领数量", width: '6%', align: "center", sortable: true }, //金杯救护车
                   { field: "ApprovalUserName", title: "审批人", width: '6%', align: "center", sortable: false }, //金杯救护车
                   {
                       field: "ApprovalTime", title: "审批时间", width: '10%', align: "center"
                       , formatter: $.formatTime, sortable: true
                   },
                   { field: "ApprovalCount", title: "审批数量", width: '6%', align: "center", sortable: true },

                 { field: "StartNumber", title: "发票起始号码", width: '8%', align: "center", sortable: false },
                 { field: "EndNumber", title: "发票截止号码", width: '8%', align: "center", sortable: false },
                     { field: "Remark1", title: "申领备注", width: '7%', align: "center", sortable: false },
                         { field: "Remark2", title: "审批备注", width: '7%', align: "center", sortable: false },
                    {
                        field: "ApprovalState", title: "审批状态", width: '8%', align: "center",
                        formatter: function (value, row, index) {
                            if (value == "已审批") {

                                return '<a   style="color:#0099FF;"  id="checkA" class="linkURL" onclick="openDetail(\'' + row.StartNumber + '\',\'' + row.EndNumber + '\',\'' + row.backup1 + '\',\'' + row.ApplyUserName + '\',\'' + row.ApprovalCount + '\' );"  href="javascript:void(0)" ></a>';
                            }
                            else {
                                return '<a   style="color:red;"  id="checkA" class="linkURLcls" onclick="openDetailURL(\'' + row.ApplyID + '\',\'' + row.backup1 + '\',\'' + row.ApplyUserName + '\',\'' + row.ApplyCount + '\' );"  href="javascript:void(0)" ></a>';
                            }
                        }, sortable: true
                    }


                ]],


                onLoadSuccess: function (data) {
                    //alert();

                    $('.linkURL').linkbutton({

                        text: '已审批',
                        plain: true,
                        iconCls: 'icon-search'
                    });
                    $('.linkURLdelete').linkbutton({
                        text: '撤销',
                        plain: true,
                        iconCls: 'icon-custom-cJinYong'
                    });

                    $('.linkURLcls').linkbutton({

                        text: '申领中',
                        plain: true,
                        iconCls: 'icon-search'
                    });

                    //当开始填写 起止发票号改变时判断共计多少个
                    getChargeSum('#txtStartNumber');
                    getChargeSum('#txtEndNumber');

                }

            });
        } //列表加载结束


        function openDetail(StartNumber, EndNumber, backup1, ApplyUserName, ApprovalCount) {
            $.messager.show({
                title: '请注意!!!',
                //return '<span style="background-color:#ffee00;color:red;">' + datenew + '</span>';
                //msg: '您已经审批给 ' + backup1 + '分中心' + ApplyUserName + '，发票号为  ' + StartNumber + '--' + EndNumber + ' <span style="background-color:#ffee00;color:red;">  共计' + ApprovalCount + ' 张 </span>发票！ '
                msg: '您已经审批给 ' + backup1 + '分站' + ApplyUserName + '，发票号为  ' + StartNumber + '--' + EndNumber + ' <span style="background-color:#ffee00;color:red;">  共计' + ApprovalCount + ' 张 </span>发票！ '
                                               , height: '200px'
                                               , width: '300px'
                                               , timeout: 3400
                                               , showType: 'slide'
                                               , style: {
                                                   right: '',
                                                   top: document.body.scrollTop + document.documentElement.scrollTop,
                                                   bottom: ''
                                               }
            });
        }

        //2016-5-26 新增删除
        function deleteDetailURL(deleterowID) {

            $.messager.confirm('提示', '您确定要撤销此条审批内容吗？', function (r) {
                if (r) {

                    document.getElementById('adelete').disabled = true;
                    $.ajax({
                        type: 'POST',

                        url: '@Url.Content("~/IM/I_InvoiceApproval/deleteApprovalInfo")',
                        data:
                            {

                                deleteRowID: deleterowID

                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                // Materials.length = 0;
                                $("#gridApprovalList").datagrid("reload");
                                document.getElementById('adelete').disabled = false;

                            }

                            );
                        }
                    });
                }
            });

        }





        function openDetailURL(ApplyID, backup1, ApplyUserName, ApplyCount) {  //打开查看按钮内容
            $('#AccidentDetailDialog').dialog('open');
            $('#txtApplyID').val(ApplyID);
            //$('#txtCenterCode').textbox('setText', backup1);
            $('#txtStationCode').textbox('setText', backup1);
            $('#txtApplyUserName').textbox('setText', ApplyUserName);
            $('#txtApplyCount').textbox('setText', ApplyCount);
            $.GID("p").style.display = "none";

        }

        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridApprovalList");
        });
    </script>
}

<div id="TableForm" class="easyui-layout" style="width:auto; height:auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:' 发票审批',iconCls:'icon-custom-cWuZiWeiHu'">
        <div id="SearchBar" data-options="region:'north'" style="overflow: hidden; padding: 10px">
            <table>
                <tr>
                    <td>日期：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-datebox" style="width: 150px" id="zAccidentTimeStart">
                    </td>
                    <td>至：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-datebox" style="width: 150px" id="zAccidentTimeEnd">
                    </td>

                    <td align="right">分中心：</td>
                    <td align="left" valign="middle">
                        <input class="easyui-combobox" style="width: 150px" id="zcenterCode">
                    </td>
                    <td align="right">分站：</td>
                    <td align="left" valign="middle">
                    <td>
                        <input id="StationID" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right">申领人：</td>
                    <td align="left" valign="middle">
                    <td>
                        <input id="personName" class="easyui-textbox" style="width:150px" />
                    </td>
                    <td>
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>
                </tr>

            </table>
        </div>

        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="gridApprovalList"></table>
        </div>

    </div>
</div>
@Html.Partial("~/Areas/IM/Views/I_InvoiceApproval/I_InvoiceApprovalDetail.cshtml")